﻿using System;
using System.Data;
using System.Data.SqlClient;
using VIT.DataHelper.DataAccess;

namespace VIT.Business
{
    public class BLFaq
    {
        SQLSupport sqlSupport = new SQLSupport();

        #region Properties
        public int Id { get; set; }
        public string LanguageId { get; set; }
        public int FaqGroupId { get; set; }
        public string Question { get; set; }
        public string Answer { get; set; }
        public string AskBy { get; set; }
        public string Email { get; set; }
        public string AnswerBy { get; set; }
        public string Address { get; set; }
        public int Orders { get; set; }
        #endregion

        public DataTable GetAll(int faqGroupId)
        {
            string strQuery = "select Id, FaqGroupId, Question, Answer, AskBy, AnswerBy, Email, Address, Orders, Published from Faq where LanguageID=@LanguageID and Deleted=0 and Published=1 and FaqGroupId=@FaqGroupId order by Orders";
            SqlParameter LanguageId = new SqlParameter("@LanguageID", this.LanguageId);
            SqlParameter FaqGroupId = new SqlParameter("@FaqGroupId", faqGroupId);
            return sqlSupport.ExecuteDataset(false, strQuery, LanguageId, FaqGroupId).Tables[0];
        }

        public bool SaveQuestion()
        {
            string sql = "insert into Faq(LanguageId, FaqGroupId, Question, AskBy, Email, Address, CreateDate) values (@LanguageId, @FaqGroupId, @Question, @AskBy, @Email, @Address, @Now)";

            SqlParameter LanguageId = new SqlParameter("@LanguageId", this.LanguageId);
            SqlParameter FaqGroupId = new SqlParameter("@FaqGroupId", this.FaqGroupId);
            SqlParameter Question = new SqlParameter("@Question", this.Question);
            SqlParameter AskBy = new SqlParameter("@AskBy", this.AskBy);
            SqlParameter Email = new SqlParameter("@Email", this.Email);
            SqlParameter Address = new SqlParameter("@Address", this.Address);
            SqlParameter Now = new SqlParameter("@Now", DateTime.Now);

            return sqlSupport.ExecuteNonQuery(false, sql, LanguageId, FaqGroupId, Question, AskBy, Email, Address, Now) > 0;
        }
    }
}
